﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ChineseSchool.Models.Hethong;
using System.Data;

namespace ChineseSchool.BLL
{
    public class B_Page
    {
        private PetaPoco.Database db;
        public B_Page()
        {
            db = new PetaPoco.Database("ConnectionString");
        }

        // Select All
        public DataTable GetAll()
        {
            DataTable dt = new DataTable();
            dt = db.ExecuteReader("EXEC Page_Get_List");
            return dt;
        }

        public List<M_Page> GetAlls()
        {
            var page = db.Fetch<M_Page>(@";EXEC Page_Get_List");
            return page;
        }

        // Select by ID
        public M_Page Selectby_id(int PageID)
        {
            var loadmenu = db.SingleOrDefault<M_Page>("SELECT * FROM Page bc WHERE bc.PageID = " + PageID + ";");
            db.CloseSharedConnection();
            return loadmenu;
        }

        public List<M_Page> GetBy_MenuID(int MenuID)
        {
            var Page = db.Fetch<M_Page>(@";EXEC Page_GetByMenuId @@MenuId = @0", MenuID);
            return Page;
        }
    }
}